package com.wenguodong.demofirstt;

import org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapProperties;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/*
 *@Time：2023/4/19
 *@Author：Jelly
 */
public class UserTValidator implements Validator {
    @Override
    public boolean supports(Class<?> clazz) {
        return UserT.class.equals(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmpty(errors, "name", "name.empty");
        UserT userT = (UserT) target;
        if (userT.getAge() < 0) {
            errors.rejectValue("age", "error value < 0");
        } else if (userT.getAge() > 110) {
            errors.rejectValue("age", "error value too old");
        }
    }
}
